package cn.com.sealevel.util;

/* loaded from: netty-mqtt-client-1.0.0.jar:cn/com/sealevel/util/DataUtil.class */
public class DataUtil {
    private static int serial = 0;

    public static String getHexStringByBytes(byte[] content) {
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < content.length; i++) {
            buf.append(String.format("%02X", Byte.valueOf(content[i])));
        }
        return buf.toString();
    }

    public static byte getByteByString(String str) {
        return (byte) Integer.parseInt(str, 16);
    }

    public static byte[] getBytesByHexString(String strData) {
        byte[] content = new byte[0];
        if (strData != null) {
            content = new byte[strData.length() / 2];
            for (int i = 0; i < strData.length() / 2; i++) {
                content[i] = getByteByString(strData.substring(2 * i, (2 * i) + 2));
            }
        }
        return content;
    }

    /* JADX WARN: Multi-variable type inference failed */
    public static int getCheckCode(byte[] data) {
        int CheckCode = data[0];
        for (int i = 1; i < data.length; i++) {
            CheckCode = (CheckCode ^ data[i]) == 1 ? 1 : 0;
        }
        return CheckCode;
    }

    public static String getStringByAscii(byte[] asc) {
        StringBuilder sb = new StringBuilder();
        for (byte b : asc) {
            sb.append((char) b);
        }
        return sb.toString().trim();
    }

    public static int getNonSignByte(byte data) {
        if (data < 0) {
            return data + 256;
        }
        return data;
    }

    /* JADX WARN: Type inference failed for: r0v10, types: [long] */
    public static long getNonSignBytes(byte[] data) {
        char c = 0;
        long length = (long) data.length;
        for (int i = 0; ((long) i) < length; i++) {
            c += ((long) getNonSignByte(data[i])) * getPower(256, (length - ((long) i)) - 1);
        }
        return c;
    }

    /* JADX WARN: Type inference failed for: r0v7, types: [long] */
    public static long getPower(long bottom, long exponent) {
        char c = 1;
        for (int i = 0; ((long) i) < exponent; i++) {
            c *= bottom;
        }
        return c;
    }

    public static int getBit(byte data, int position) {
        return getNonSignByte((byte) ((data >> (8 - position)) & 1));
    }

    public static int getBits(byte data, int start, int end) {
        int paramData = 0;
        for (int i = start; i <= end; i++) {
            paramData = (int) (((double) paramData) + (((double) getBit(data, i)) * Math.pow(2.0d, (double) (end - i))));
        }
        return getNonSignByte((byte) paramData);
    }

    public static byte getByte(byte[] data, int position) {
        return data[position - 1];
    }

    public static String parseHex(byte[] data, boolean flag) {
        return getHexStringByBytes(data);
    }

    public static String getTime(byte[] data) {
        if (data == null) {
            return "";
        }
        String time = "20";
        for (int i = 0; i < data.length; i++) {
            time = time + String.format("%02d", Byte.valueOf(data[i]));
        }
        return time;
    }

    public static int getSerial() {
        if (serial < 0 || serial >= 65535) {
            serial = 0;
        }
        serial++;
        return serial;
    }

    public static void main(String[] args) {
    }
}
